package com.jic.market.mapper;

import java.lang.Long;
import java.util.List;

import com.jic.market.entity.DiscountProductDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 优惠商品明细表
 * @author : 
 * @email : 
 * @since : 2020-04-10 07:19:34
 * @version : v1.0.0
 */
@Mapper
public interface  DiscountProductDetailMapper {

    long insert(DiscountProductDetail discountProductDetail);

    long delete(Long id);

    long update(DiscountProductDetail discountProductDetail);

    DiscountProductDetail queryByPrimaryKey(Long id);

    List<DiscountProductDetail> query(DiscountProductDetail discountProductDetail);

    List<DiscountProductDetail> queryPage(@Param("startIndex") int startIndex, @Param("limit") int limit, @Param("discountProductDetail") DiscountProductDetail discountProductDetail);

    long queryPageCount(DiscountProductDetail discountProductDetail);

    @Select("select sum(d.num) from discount_promotion_detail m LEFT JOIN discount_product_detail d ON m.order_no = d.order_no and m.sku_id=d.sku_id where d.third_user_id = #{thirdUserId} and m.promotion_id=#{promotionId} and m.sku_id = #{skuId} and m.delete_flag=0 and d.delete_flag=0")
    Integer countNumByPromotionIdAndSkuIdAndThirdUserId(@Param("promotionId")String promotionId, @Param("skuId")Long skuId, @Param("thirdUserId")String thirdUserId);

    @Select("select sum(d.num) from discount_promotion_detail m LEFT JOIN discount_product_detail d ON m.order_no = d.order_no and m.sku_id=d.sku_id where m.promotion_id=#{promotionId} and m.sku_id = #{skuId} and m.delete_flag=0 and d.delete_flag=0")
    Integer countNumByPromotionIdAndSkuId(@Param("promotionId")String promotionId, @Param("skuId")Long skuId);
}